package com.test0103.test02;

public class Company {
    private String com_name;
    private Department[] departments = new Department[2];
    private int index=0;

    public Company() {
    }

    public Company(String com_name) {
        this.com_name = com_name;
    }

    public String getCom_name() {
        return com_name;
    }

    public void setCom_name(String com_name) {
        this.com_name = com_name;
    }

    @Override
    public String toString() {
        return
                "公司名:" + com_name ;

    }
    public void addDepartment(Department department){
        departments[index++]=department;
    }
    public Department getDepartmentByName(String dep_name){
        for(int i=0;i<departments.length;i++){
            if(departments[i].getName().equals(dep_name)){
                return departments[i];
            }
        }
        return null;
    }
    public Position getPositionByName(String pos_name){
        for(int i=0;i<departments.length;i++){
            for(int j=0;j<departments[i].getPositions().length;j++){
                if(pos_name.equals(departments[i].getPositions()[j].getName())){
                    return departments[i].getPositions()[j];
                }
            }

        }
        return null;
    }
    public Employee getEmployeeByName(String emp_name){
        for(int i=0;i<departments.length;i++){
            for(int j=0;j<departments[i].getPositions().length;j++){
                for(int m=0;m<departments[i].getPositions()[j].getEmployees().length;m++){
                    if(emp_name.equals(departments[i].getPositions()[j].getEmployees()[m].getName())){
                        return departments[i].getPositions()[j].getEmployees()[m];
                    }
                }
            }
        }
        return null;
    }

}
